home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / multinh1.cpp < prev    next >
C/C++ Source or Header  |  1992-01-18  |  2KB  |  67 lines

  1.                                    // Chapter 9 - Program 1
  2. #include <iostream.h>
  3.  
  4. class moving_van {
  5. protected:
  6.    float payload;
  7.    float gross_weight;
  8.    float mpg;
  9. public:
  10.    void initialize(float pl, float gw, float in_mpg) {
  11.         payload = pl;
  12.         gross_weight = gw;
  13.         mpg = in_mpg; };
  14.    float efficiency(void) {
  15.         return(payload / (payload + gross_weight)); };
  16.    float cost_per_ton(float fuel_cost) {
  17.         return(fuel_cost / (payload / 2000.0)); };
  18. };
  19.  
  20.  
  21. class driver {
  22. protected:
  23.    float hourly_pay;
  24. public:
  25.    void initialize(float pay) {hourly_pay = pay; };
  26.    float cost_per_mile(void) {return(hourly_pay / 55.0); } ;
  27. };
  28.  
  29.  
  30. class driven_truck : public moving_van, public driver {
  31. public:
  32.    void initialize_all(float pl, float gw, float in_mpg, float pay)
  33.         { payload = pl;
  34.           gross_weight = gw;
  35.           mpg = in_mpg;
  36.           hourly_pay = pay; };
  37.    float cost_per_full_day(float cost_of_gas) {
  38.           return(8.0 * hourly_pay +
  39.                 8.0 * cost_of_gas * 55.0 / mpg); };
  40. };
  41.  
  42.  
  43. main()
  44. {
  45. driven_truck chuck_ford;
  46.  
  47.    chuck_ford.initialize_all(20000.0, 12000.0, 5.2, 12.50);
  48.  
  49.    cout << "The efficiency of the Ford is " <<
  50.            chuck_ford.efficiency() << "\n";
  51.  
  52.    cout << "The cost per mile for Chuck to drive is " <<
  53.            chuck_ford.cost_per_mile() << "\n";
  54.  
  55.    cout << "The cost of Chuck driving the Ford for a day is " <<
  56.            chuck_ford.cost_per_full_day(1.129) << "\n";
  57. }
  58.  
  59.  
  60.  
  61.  
  62. // Result of execution
  63. //
  64. // The efficiency of the Ford is .625
  65. // The cost per mile for Chuck to drive is 0.227273
  66. // The cost of Chuck driving the Ford for a day is 195.530762
  67.